<template>
  <div class="reportFormPage">
    <div id="domid" class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">砂浆抗压强度试验检测记录表</div>
        <div class="codeText">
          <tr>
            BGLQ05002F
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="85%" class="text-center" colspan="3">
                <span>{{ form.gongcmc }}</span>
              </td>
            </tr>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="85%" class="text-center" colspan="3">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验日期</span>
              </td>
              <td width="35%" class="text-center">{{ form.shiyrq }}</td>

              <td align="center" style="width: 15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" class="height100" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" class="height100" style="width: 15%" />%RH
              </td>
            </tr>
            <tr>
              <td height="25" align="center">检测依据</td>
              <td>
                <el-input type="textarea" v-model="form.jiancyj" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center">判定依据</td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="586px" class="middle-table">
          <tbody>
            <tr trindex="0" width="100%">
              <td width="22%" colspan="3" height="30">设计强度等级</td>
              <td width="22%" colspan="2" height="30">
                <el-select clearable v-model="form.shejqddj" @change="qddjChange()" class="hide-icon">
                  <el-option v-for="item in qddjList" :key="item.syYjName" :label="item.syYjName" :value="item.syYjName" />
                </el-select>
              </td>
              <td width="14%" colspan="2" height="30">试件尺寸(mm)</td>
              <td width="22%" colspan="3" height="30">
                <span>70.7x70.7x70.7</span>
                <!--                <el-input v-model="form.shijcc" @blur="setqdbgform()" />-->
              </td>
              <td width="8%" height="30">稠度(mm)</td>
              <td colspan="2" height="30">
                <el-input v-model="form.choud" type="Number" @blur="setqdbgform()" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" />
              </td>
            </tr>

            <tr trindex="1">
              <td colspan="3" height="30">拌合方式</td>
              <td colspan="2" height="30">
                <el-input v-model="form.banhfs" @blur="setqdbgform()" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" />
              </td>
              <td colspan="2" height="30">养护方式</td>
              <td colspan="3" height="30">
                <el-input v-model="form.yanghfs" @blur="setqdbgform()" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" />
              </td>
              <td colspan="1" height="30">换算系数</td>
              <td colspan="2" height="30">
                <el-select clearable v-model="huansxs" @change="huansxsChange()" class="hide-icon">
                  <el-option v-for="item in huansxsoption" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </td>
            </tr>
            <tr trindex="2" width="100%">
              <td colspan="1" rowspan="2">试件编号</td>
              <td colspan="2" rowspan="2" width="15%">取样部位</td>
              <td colspan="2" rowspan="2" width="15%">制件日期</td>
              <td colspan="2" rowspan="2" width="15%">试验日期</td>
              <td rowspan="2" width="7%">龄期(天)</td>
              <td rowspan="2" width="8%">极限载荷(kN)</td>
              <td colspan="2">抗压强度(MPa)</td>
              <td colspan="2" rowspan="2" width="15%">占设计强度百分率(%)</td>
            </tr>
            <tr trindex="3" width="100%">
              <td height="30" width="7%">单值</td>
              <td height="30" width="7%">平均</td>
            </tr>

            <tr trindex="0" width="100%" v-for="(e, index) in list" :key="index">
              <td>{{ e.shijbh }}</td>
              <td colspan="2" rowspan="3" v-if="index % 3 == 0">
                  <!-- {{ `${(index / 3) * 3 + 2}_0` }} -->
                <el-input v-model="e.quybw"  @keydown.native="handleKeyDown($event, (index / 3) * 3 + 2, 0)" :ref="`${(index / 3) * 3 + 2}_0`" />
              </td>
              <td colspan="2" rowspan="3" v-if="index % 3 == 0">
                <el-date-picker class="hide-icon" value-format="yyyy/MM/dd" format="yyyy/MM/dd" style="width: 100%" v-model="e.zhijrq" @change="changesyrq(e)" />
              </td>
              <td colspan="2" rowspan="3" v-if="index % 3 == 0" width="23%">
                {{ e.shiyrq }}
              </td>
              <td rowspan="3" v-if="index % 3 == 0">
                <el-select class="hide-icon" clearable v-model="e.lingq" @change="changesyrq(e)" style="height: 100%">
                  <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </td>
              <td>
                   <!-- {{ `${index + 2}_${index % 3 == 0 ? 1 : 0}` }} -->
                <el-input type="Number" v-model="e.jixzh" @blur="handlekangyqd(e, index, true)" @keydown.native="handleKeyDown($event, index  + 2, index % 3 == 0 ? 1 : 0)" :ref="`${index+ 2}_${index % 3 == 0 ? 1 : 0}`" />
              </td>
              <td>{{ e.kangyqdcz }}</td>
              <td rowspan="3" v-if="index % 3 == 0">{{ e.pingjkyqd }}</td>
              <td colspan="2" rowspan="3" v-if="index % 3 == 0" width="15%">{{ e.zhansjqdbfl }}</td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="60px" class="bottom-table">
          <tr>
            <td>
              <el-input type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import { handleFocus, emptyConvert, handleKeyDown } from "@/views/reportForms/utils";
import { getSjKyqdBsInfo, getQddj } from "@/api/reportsj/sjKyqdBsInfo";
import Bus from "@/utils/bus";
import decimal from "@/utils/big-decimal";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";

export default {
  name: "bhw",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  data() {
    return {
      huansxs: 1,
      lingq: undefined,
      qddjList: {},
      list: [
        { shijbh: "", index: 1, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 2, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 3, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 4, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 5, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 6, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 7, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 8, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 9, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 10, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 11, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 },
        { shijbh: "", index: 12, quybw: "", zhijrq: "", shiyrq: "", jixzh: "", kangyqdcz: "", pingjkyqd: "", zhansjqdbfl: "", huansxs: 1 }
      ],
      quybw: null,
      huansxsoption: [
        { value: 1, label: "1" },
        { value: 1.35, label: "1.35" }
      ],
      options: [
        { value: 3, label: "3" },
        { value: 7, label: "7" },
        { value: 28, label: "28" }
      ],
      jilbh: "",
      form: {
        shiyrq: "",
        gongcbwyt: "",
        baogbh: "",
        jiancdwmc: "",
        totalPage: "",
        page: "",
        jiancyj: "",
        zhuyyqsbmcjbh: "",
        gongcmc: "",
        yangpmc: "",
        yangpbh: "",
        laiysj: "",
        yangpsl: "",
        yangpzt: ""
      },
      twoTableData: {},
      threeTableData: {},
      fjsm: "附加声明：",
      dateText: "2024年05月10日",
      readonly: false
    };
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: [String, Number],
      default: () => ""
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    },
    syType: {
      type: [String, Number],
      default: () => ""
    }
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created() {
    this.getInfo();
    this.getQddj();
  },
  methods: {
    setqdbgform() {
      Bus.$emit("setqdbgform", this.form);
    },
    //查询砂浆强度等级列表；
    getQddj() {
      getQddj("砂浆强度等级").then((res) => {
        this.qddjList = res.data;
      });
    },
    qddjChange() {
      Bus.$emit("setqdbgform", this.form);
      this.form.detailList.forEach((e) => {
        if (e.kangyqdcz && this.form.shejqddj) {
          e.guidz = "≥" + this.form.shejqddj.substring(1);
        }
      });
      this.huansxsChange();
    },

    // 获取详情
    getInfo() {
      if (!this.excelId) {
        return;
      }
      getSjKyqdBsInfo(this.excelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
        // Bus.$emit("setqdbgform", this.form);
        if (this.form.detailList) {
          this.list = this.form.detailList;
          this.huansxs = this.list[0].huansxs || 1;
          for (let i = 0; i < 12; i++) {
            this.list[i].shijbh = this.handleshijbh(i + 1);
          }
          this.form.detailList.forEach((e) => {
            if (e.kangyqdcz && this.form.shejqddj) {
              e.guidz = "≥" + this.form.shejqddj.substring(1);
            }
          });
          // this.huansxsChange();
        }
      });
    },
    submitForm() {
      this.form.detailList = [];
      for (let i = 0; i < 12; i++) {
        let item = this.list[i];
        if (i <= 9 && (i + 3) % 3 == 0) {
          this.list[i + 1].quybw = this.list[i + 2].quybw = item.quybw;
          this.list[i + 1].zhijrq = this.list[i + 2].zhijrq = item.zhijrq;
          this.list[i + 1].pingjkyqd = this.list[i + 2].pingjkyqd = item.pingjkyqd;
          this.list[i + 1].zhansjqdbfl = this.list[i + 2].zhansjqdbfl = item.zhansjqdbfl;
          this.list[i + 1].lingq = this.list[i + 2].lingq = item.lingq;
          this.list[i + 1].shiyrq = this.list[i + 2].shiyrq = item.shiyrq;
        }
        if (item.jixzh || item.quybw || item.lingq || item.shiyrq) {
          let e = item;
          e.huansxs = this.huansxs || 1;
          this.form.detailList.push(e);
        }
      }
      return this.form;
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      // this.$set(this.form, 'jiancyj', info.label);
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setSjBgJiancyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setSjBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    //制件日期改变
    changesyrq(item) {
      //计算试验日期；
      if (item.zhijrq && item.lingq) {
        let syrq = new Date(item.zhijrq);
        syrq.setDate(syrq.getDate() + parseInt(item.lingq));
        let year = syrq.getFullYear();
        let month = syrq.getMonth() + 1; // 获取月份，需要+1因为从0开始计数
        let day = syrq.getDate(); // 获取日
        item.shiyrq = `${year}/${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}`;
      } else {
        item.shiyrq = undefined;
      }
    },
    //换算系数改变
    huansxsChange() {
      this.list.forEach((item, index) => {
        if (item.jixzh) {
          this.handlekangyqd(item, index);
        }
      });
      Bus.$emit("setSjkyqdsyrq", this.list);
    },
    // 计算单值
    handlekangyqd(e, i, state) {
      if (e.jixzh && this.huansxs) {
        let area = 4998.49;
        e.kangyqdcz = decimal.divide(decimal.multiply(1000, decimal.multiply(this.huansxs, e.jixzh, 9), 9), area, 1);
      } else {
        e.kangyqdcz = undefined;
      }
      this.computeAvg();
      Bus.$emit("setSjkyqdsyrq", this.list);
    },
    //计算有效平均值
    computeAvg() {
      let list = this.list;
      //小于3条的数据不计算平均值
      if (list.length < 3) {
        return;
      }
      for (let i = 0; i < list.length; i++) {
        if (i % 3 == 2) {
          if (list[i].kangyqdcz && list[i - 1].kangyqdcz && list[i - 2].kangyqdcz) {
            let a = parseFloat(list[i].kangyqdcz),
              b = parseFloat(list[i - 1].kangyqdcz),
              c = parseFloat(list[i - 2].kangyqdcz);
            let mid = this.computeMid(a, b, c);
            let max = Math.max(a, b, c);
            let min = Math.min(a, b, c);
            if (max - mid > mid * 0.15 && mid - min > mid * 0.15) {
              this.list[i].pingjkyqd = this.list[i - 1].pingjkyqd = this.list[i - 2].pingjkyqd = "无效";
              this.list[i].zhansjqdbfl = this.list[i - 1].zhansjqdbfl = this.list[i - 2].zhansjqdbfl = "-";
              this.list[i].jiegpd = this.list[i - 1].jiegpd = this.list[i - 2].jiegpd = "无效";
              if (this.form.shejqddj) {
                this.list[i].guidz = this.list[i - 1].guidz = this.list[i - 2].guidz = "≥" + this.form.shejqddj.substring(1);
              }
            } else if (max - mid < mid * 0.15 && mid - min < mid * 0.15) {
              //取三个数平均值
              this.list[i].pingjkyqd = this.list[i - 1].pingjkyqd = this.list[i - 2].pingjkyqd = decimal.divide(decimal.add(decimal.add(max, min), mid), 3);
              //计算占比
              this.list[i].zhansjqdbfl = this.list[i - 1].zhansjqdbfl = this.list[i - 2].zhansjqdbfl = decimal.divide(this.list[i].pingjkyqd * 100, parseFloat(this.form.shejqddj.substring(1)), 1);
              if (this.list[i].pingjkyqd - parseFloat(this.form.shejqddj.substring(1)) >= 0) {
                this.list[i].jiegpd = this.list[i - 1].jiegpd = this.list[i - 2].jiegpd = "合格";
              } else {
                this.list[i].jiegpd = this.list[i - 1].jiegpd = this.list[i - 2].jiegpd = "不合格";
              }
              if (this.form.shejqddj) {
                this.list[i].guidz = this.list[i - 1].guidz = this.list[i - 2].guidz = "≥" + this.form.shejqddj.substring(1);
              }
            } else {
              this.list[i].pingjkyqd = this.list[i - 1].pingjkyqd = this.list[i - 2].pingjkyqd = mid;
              //计算占比
              this.list[i].zhansjqdbfl = this.list[i - 1].zhansjqdbfl = this.list[i - 2].zhansjqdbfl = decimal.divide(mid * 100, parseFloat(this.form.shejqddj.substring(1)), 1);
              if (mid - parseFloat(this.form.shejqddj.substring(1)) >= 0) {
                this.list[i].jiegpd = this.list[i - 1].jiegpd = this.list[i - 2].jiegpd = "合格";
              } else {
                this.list[i].jiegpd = this.list[i - 1].jiegpd = this.list[i - 2].jiegpd = "不合格";
              }
              if (this.form.shejqddj) {
                this.list[i].guidz = this.list[i - 1].guidz = this.list[i - 2].guidz = "≥" + this.form.shejqddj.substring(1);
              }
            }
          } else {
            if (list[i].kangyqdcz || list[i - 1].kangyqdcz || list[i - 2].kangyqdcz) {
              this.list[i].pingjkyqd = this.list[i - 1].pingjkyqd = this.list[i - 2].pingjkyqd = "无效";
              this.list[i].zhansjqdbfl = this.list[i - 1].zhansjqdbfl = this.list[i - 2].zhansjqdbfl = "-";
              this.list[i].jiegpd = this.list[i - 1].jiegpd = this.list[i - 2].jiegpd = "无效";
              if (this.form.shejqddj) {
                this.list[i].guidz = this.list[i - 1].guidz = this.list[i - 2].guidz = "≥" + this.form.shejqddj.substring(1);
              }
            }
          }
        }
      }
    },

    computeMid(a, b, c) {
      let sortedNumbers = [a, b, c].sort((x, y) => x - y);
      return sortedNumbers[1];
    },
    // 计算平均值
    computeMean(item, i) {
      const list = this.list;
      if (!list[i]) {
        return;
      }
      let index1 = 0;
      let index2 = 0;
      let index3 = 0;
      if (i % 3 == 0) {
        index1 = i;
        index2 = i + 1;
        index3 = i + 2;
      }
      if (i % 3 == 1) {
        index1 = i - 1;
        index2 = i;
        index3 = i + 1;
      }
      if (i % 3 == 2) {
        index1 = i - 2;
        index2 = i - 1;
        index3 = i;
      }
      let count = 0;
      let sum = 0;
      if (list[index1].kangyqdcz) {
        count++;
        sum += parseFloat(list[index1].kangyqdcz);
      }
      if (list[index2].kangyqdcz) {
        count++;
        sum += parseFloat(list[index2].kangyqdcz);
      }
      if (list[index3].kangyqdcz) {
        count++;
        sum += parseFloat(list[index3].kangyqdcz);
      }
      let avg = decimal.divide(parseFloat(sum), count);
      list[index1].pingjkyqd = list[index2].pingjkyqd = list[index3].pingjkyqd = avg;
      list[index1].zhansjqdbfl = list[index2].zhansjqdbfl = list[index3].zhansjqdbfl = decimal.divide(avg * 100, 10);
      this.list = list;
    },

    // 编号处理
    handleshijbh(index) {
      return Math.ceil(index / 3).toString() + "-" + (index % 3 == 0 ? 3 : index % 3).toString();
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]?.length) {
        this.$refs[ref][0].focus();
      } else if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped lang="scss">
</style>
